import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store/index";
Vue.use(VueRouter);

const routes = [
  // //////默认路由跳转/index/////
  {
    path: "/",
    redirect: "/index",
  },
  //////////////////////////////////

  //////   个人中心////////////
  {
    path: "/register",
    name: "register",
    component: () => import("../views/Register.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue"),
  },
  {
    path: "/my",
    name: "my",
    //路由守卫  如果isLogin为false则为未登录状态  跳转登录页面
    beforeEnter: (to, from, next) => {
      if (to.path==='/login') {
        next();
        var tokenStr=window.sessionStorage.getItem('token')
      }
      if(!tokenStr){
        next()
      } else {
        next("/login");
      }
    },
    component: () => import("../views/My.vue"),
  },
  //////   购物车////////////
  {
    path: "/shop",
    name: "shop",
    component: () => import("../views/Shop.vue"),
  },
  //////   首页////////////
  {
    path: "/index",
    name: "index",
    component: () => import("../views/Index.vue"),
  },
  //////   全部商品////////////
  {
    path: "/all",
    name: "all",
    component: () => import("../views/All.vue"),
  }, //////   基本信息////////////
  {
    path: "/information",
    name: "information",
    component: () => import("../components/My/BasicInformation.vue"),
  },
  {
    path: "/myorder",
    name: "myorder",
    component: () => import("../components/My/MyOrder.vue"),
  },
    //////   基本信息////////////
    {
        path: '/information',
        name: 'information',
        component: () => import('../components/My/BasicInformation.vue'),
    },
    //////  积分
    {
      path: '/points',
      name: 'Points',
      component: () => import('../components/My/CreditsExchange.vue'),
    },
    //////   成长值  ////////////
    {
        path: '/memberinfo',
        name: 'MemberInformation',
        component: () => import('../components/My/MemberInformation.vue'),
    },
    /////// 全部订单 ////////
    {
      path: '/myorder',
      name: 'MyOrder',
      component: () => import('../components/My/MyOrder.vue'),
    },
    ///////// 详情页 /////////
    {
      path: '/productdetails',
      name: 'routeName',
      component: () => import('../components/Index/ProductDetail.vue'),
    },
  //   {
  //     path: '/',
  //     name: 'home',
  //     component: HomeView
  //   },
  //   {
  //     path: '/about',
  //     name: 'about',
  //     // route level code-splitting
  //     // this generates a separate chunk (about.[hash].js) for this route
  //     // which is lazy-loaded when the route is visited.
  //     component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  //   }

];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// router.beforeEach((to, from) => {
//   if (to.path == "/login") {
//     store.state.isMyBottom = false;
//   } else {
//     store.state.isMyBottom = true;
//   }
// });

export default router;
